home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Graphics / Icons / next-icon@gun.com / Apps / creating.dir.tiffs.rtfd / link.dir.tiffs < prev    next >
Text File  |  1994-12-04  |  5KB  |  186 lines

  1. #!/bin/sh
  2. #
  3. # Go through a hierarchy of folders and icons and create links called
  4. # .dir.tiff that point to some image in each folder.
  5. #
  6. # Expects the hierarchy Section/Folder/image.tiff.
  7. #
  8.  
  9. PROG="`basename $0`"
  10. USAGE="${PROG} folder [folders...]"
  11. VERSION="Sun Dec  4 16:10:56 EST 1994"
  12.  
  13. #
  14. # Print help if no arguments
  15. test $# = 0 && {
  16.     cat << EOF
  17.  
  18.     USAGE: ${USAGE}
  19.  
  20.     ${PROG} is a utility that creates .dir.tiff and .opendir.tiff
  21.     links in a two-level image archive set up like the
  22.     NeXT-icon@gun.com multimedia mailing list archives.  Command
  23.     line arguments consist of a top-level folder names that
  24.     contains lower level folders each containing at least one
  25.     TIFF image.
  26.  
  27.     The hierarchy should be set up as follows:
  28.  
  29.         Section/section.dir.tiff
  30.         Section/section.opendir.tiff
  31.         Section/Folder1/image1.tiff
  32.         Section/Folder1/image2.tiff
  33.         Section/Folder2/anotherimage.dir.tiff
  34.         Section/Folder3/onemoreimage.tiff
  35.  
  36.     ${PROG} will create .dir and .opendir.tiff links in the
  37.     first Section level and each lower Folder level, but will
  38.     not proceed into third or lower levels, regardless of
  39.     whether they level exists.
  40.  
  41.     ${PROG} attempts to create .dir.tiff and .opendir.tiff
  42.     links using the following criteria:
  43.  
  44.         If .opendir.tiff does not exist, do the following:
  45.  
  46.         if a TIFF image with the same name as it's folder
  47.             exists with a .opendir.tiff extension, then link
  48.             .opendir.tiff to it.
  49.  
  50.         If .dir.tiff does not exist, do the following:
  51.  
  52.         If a TIFF image with the same name as it's folder
  53.             exists, with a .dir.tiff extension, then link
  54.             .dir.tiff to it.
  55.  
  56.         If a TIFF image with the same name as it's folder
  57.             exists without a .dir.tiff extension, then link
  58.             .dir.tiff to it.
  59.  
  60.         If any TIFF images exist in the folder, link
  61.             .dir.tiff to the first one in the directory.
  62.  
  63.     BUGS
  64.     ${PROG} must be run from a UNIX prompt, and cannot be run
  65.     from the Workspace.
  66.  
  67.     Should have a front end.
  68.  
  69.     By Timothy Reed <treed@bmt.gun.com>, $VERSION
  70.     Thanks to Howard Ship <hship@sinistar.cac.stratus.com> for telling me
  71.     present the next-icon@gun.com archives this way.
  72.  
  73.     For information on subscribing to the list, send a message with the word
  74.     'subscribe' or 'help' to NeXT-icon-request@gun.com.
  75.  
  76. EOF
  77.  
  78. }
  79.  
  80. #
  81. # For each folder specified on the command line.
  82. for SECTION in $* ; do
  83.     #
  84.     # Check if $SECTION is a folder, and continue to the next one if not.
  85.     test ! -d ${SECTION} && { 
  86.         echo "${PROG}: No such folder ${SECTION}.  Continuing to next folder."
  87.         continue
  88.     }
  89.     #
  90.     # Run this in a subshell, since we're entering each SECTION one at a time
  91.     ( 
  92.         cd ${SECTION}
  93.         #
  94.         # Take care of .opendir.tiff first, since it is a less-critical and 
  95.         # difficult to locate file.
  96.         test ! -f .opendir.tiff && {
  97.             if test -f ${SECTION}.opendir.tiff ; then
  98.                 echo "${PROG}: Linking ${SECTION}.opendir.tiff to .opendir.tiff"
  99.                 ln -s ${SECTION}.opendir.tiff .opendir.tiff
  100.             fi
  101.             }
  102.         test ! -f .dir.tiff && {
  103.             if test -f ${SECTION}.dir.tiff ; then
  104.                 # Get the file named ${SECTION}.dir.tiff first.
  105.                 FIRST_FILE=${SECTION}.dir.tiff
  106.             elif test -f ${SECTION}.tiff ; then
  107.                 # If SECTION.dir.tiff doesn't exist, get the file named ${SECTION}.tiff.
  108.                 FIRST_FILE=${SECTION}.tiff
  109.             else
  110.                 # Now try to get the first tiff file in the directory.
  111.                 FIRST_FILE="`echo *.tiff 2>/dev/null | awk '{print $1}' 2>/dev/null`"
  112.             fi
  113.             test "${FIRST_FILE}" != '*.tiff' && {
  114.                 echo "Linking ${FIRST_FILE} to .dir.tiff"
  115.                 ln -s ${FIRST_FILE} .dir.tiff
  116.                 }
  117.  
  118.             # If tiff doesn't appear as the first word, skip to the next one.
  119.             test -z "${FIRST_FILE}" && {
  120.                 echo "${PROG}: No images in ${SECTION}/${DIR}."
  121.                 continue
  122.                 }
  123.             }
  124.         for DIR in * ; do
  125.             #
  126.             # If this is not a directory, skip on to the next one.
  127.             test ! -d ${DIR} && {
  128. #                echo "$DIR is not a directory."
  129.             continue
  130.               }
  131.             #
  132.             # Run this in a subshell, since we're entering each subdirectory one at 
  133.             # a time.
  134.           (
  135.                 # Skip to the next one if this directory already contains a .dir.tiff.
  136.                 # We don't care so much about .opendir.tiff files.
  137.                 test -f ${DIR}/.dir.tiff && {
  138. #                    echo "${SECTION}/${DIR} already contains a .dir.tiff"
  139.                     continue
  140.                 }
  141.  
  142.                 # Enter the subdirectory.
  143.                 cd $DIR
  144.  
  145.                 # Get the first tiff file in the directory.
  146.                 FIRST_FILE="`echo *.tiff 2>/dev/null | awk '{print $1}' 2>/dev/null`"
  147.  
  148.                 # If tiff doesn't appear as the first word, skip to the next one.
  149.                 test -z "${FIRST_FILE}" && {
  150.                     echo "No tiffs in ${SECTION}/${DIR}."
  151.                     continue
  152.                     }
  153.  
  154.                 # Create .opendir.tiff first, since we continue regardless of whether
  155.                 # this is successful.
  156.                 test ! -f .opendir.tiff && {
  157.                     for EXT in opendir.tiff ; do
  158.                         test -f ${DIR}.opendir.tiff && {
  159.                             echo "Linking ${SECTION}/${DIR}/${DIR}.${EXT} to .opendir.tiff"
  160.                             ln -s ${DIR}.${EXT} .opendir.tiff
  161.                         }
  162.                     done
  163.                     }
  164.  
  165.                 # Check for directoryname.dir.tiff and directoryname.tiff.
  166.                 for EXT in dir.tiff tiff ; do
  167.                     test -f ${DIR}.${EXT} && {
  168.                         echo "Linking ${SECTION}/${DIR}/${DIR}.${EXT} to .dir.tiff"
  169.                         ln -s ${DIR}.${EXT} .dir.tiff
  170.                         continue
  171.                         }
  172.                 done
  173.                 test ! -f "${FIRST_FILE}" && { 
  174. #                    echo "${FIRST_FILE} is not a file."
  175.                     continue
  176.                     }
  177.                 test ! -f .dir.tiff && { 
  178.                     echo "Linking ${SECTION}/${DIR}/${FIRST_FILE} to .dir.tiff"
  179.                     ln -s ${FIRST_FILE} .dir.tiff
  180.                     }
  181.             )
  182.         done
  183.     echo "Completed section ${SECTION}"
  184.     )
  185. done
  186.